<template>
  <div>
    <div v-if="errorMsg" class="login-error">
      <p>登录失败: <span style="color:red">{{ errorMsg }}</span></p>
    </div>
  </div>
</template>
<script>
// import { getTokenlogin, tokenConfig } from '@/api/user'
// import { setTokenConfig, getTokenConfig } from '@/util/auth'
import { callBack } from '@/api/login/index'
import { setSsoToken } from '@/util/auth'
export default {
  name: 'Back',
  data() {
    return {
      errorMsg: ''
    }
  },
  mounted() {
    this.login()
  },
  methods: {
    login() {
      const ssotoken = (this.$route.query.ssotoken || '').replace(/["']/g, '')
      const path = this.$route.query.path || '/'
      console.log(path)
      if (ssotoken) {
        // 模拟登录
        setSsoToken(ssotoken)
        callBack().then(res => {
          this.$store.dispatch('SaveToken', res.data).then(() => {
            this.$router.replace(path)
          })
        })
      } else {
        this.errorMsg = '缺少参数ssotoken'
      }
    }
  }
}
</script>

<style  scope>
.login-error {
  display: flex;
  color: red;
  margin: 10px;

  .return-btn {
    margin-left: 10px;
  }
}
</style>
